package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     *
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);


    /**
     * 新增套餐
     */
    @Insert("INSERT INTO setmeal (name, category_id, price, image, description, create_time, update_time, create_user,update_user, status)" +
            "values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{createTime}, #{updateTime}, #{createUser},#{updateUser}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @AutoFill(OperationType.INSERT)
    void insert(Setmeal s);


    /**
     * 分页查询
     */
    List<SetmealVO> page(SetmealPageQueryDTO s);


    /**
     * 根据id查询对应套餐信息
     */
    @Select("SELECT * FROM setmeal WHERE id=#{id}")
    SetmealVO getById(Long id);

    /**
     * 修改套餐--基本信息
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    @Delete("DELETE FROM setmeal WHERE id =#{id}")
    void deleteId(Long id);



    /**
     * Pc 端 条件查询
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * PC 根据套餐id查询包含的菜品列表
     */

    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long id);



    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
